package com.woniuxy.loanapprovals.controller;

import com.woniuxy.entity.*;
import com.woniuxy.loanapprovals.service.LoanApprovalService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 审核模块
 */
@RestController
@RequestMapping("/loanapprovals")
public class LoanApprovalController {

    @Resource
    LoanApprovalService loanApprovalService;


    /*
    添加
     */
    @GetMapping("/addLoanApproval")
    public LoanApproval addApproval(LoanApproval loanApproval) {

        BusinessInfo businessInfo = new BusinessInfo();
        businessInfo.setBusiness_name("蜗牛学园");      //设置企业信息

        ApprovalRole approvalRole = new ApprovalRole();
        approvalRole.setApproverName("zhangsan");       //设置审核人

        PreLoan preLoan = new PreLoan();
        preLoan.setProcess_status("1");     //设置流程状态

        CreditResult creditResult = new CreditResult();
        creditResult.setOpinionResult(true);        //授信结果

       // loanApproval.setState_audit();
        loanApproval.setOpinion("同意了");
        loanApproval.setEnterprise_id(businessInfo.getBusiness_name());     //设置企业信息
        loanApproval.setAudit_id(approvalRole.getApproverName());       //设置审核人
        loanApproval.setCredit_id(creditResult.getOpinionResult());        //设置授信结果
        loanApproval.setState_audit(true);

        loanApprovalService.addApproval(loanApproval);


        System.out.println("++++++++"+loanApproval.getOpinion()+"++++++++++");

        return loanApproval;
    }

    /*
    查询全部
     */
    @GetMapping("/allLoanApproval")
    public List<LoanApproval> selectAllLoanApproval(){

        List<LoanApproval> loanApprovals = loanApprovalService.selectAllLoanApproval();

        return loanApprovals;
    }

    /*
    根据id查询
     */
    @GetMapping("/loanApprovalById/{id_loan}")
    public LoanApproval selectLoanApprovalById(@PathVariable("id_loan")int id_loan){

        return loanApprovalService.selectLoanApprovalById(id_loan);
    }

    /*
    根据id删除
     */
    @DeleteMapping("/delete/{id_loan}")
    public void deleteLoanApprovalById(@PathVariable("id_loan")int id_loan){

        loanApprovalService.deleteLoanApprovalById(id_loan);
    }

    /*
    修改状态---即审核通过或不通过
     */
    @PutMapping("/update/{id_loan}")
    public LoanApproval updateLoanApprovalById(@PathVariable("id_loan")int id_loan){

        LoanApproval loanApproval=new LoanApproval();
        loanApproval.setId_loan(id_loan);
        loanApprovalService.updateLoanApprovalById(loanApproval);
        return loanApproval;
    }
}
